export function GenRanSrt(l){
  const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  let result = '';
  if (l <= 0) {
    l = 6
  }
  for (let i = 0; i < l; i++) {
    result += chars.charAt(Math.floor(Math.random() * chars.length));
  }
  return result;
}
//广告位类型
export function SelSlotType(stype){
  if (stype == 1){
    return '信息流'
  }else if (stype == 2){
    return 'Banner'
  }else if (stype == 3){
    return '开屏'
  }else if (stype == 4){
    return '视频'
  }else if (stype == 5){
    return '横幅'
  }else if (stype == 6){
    return '插屏'
  }else if (stype == 7){
    return '暂停'
  }else if (stype == 8){
    return '贴片'
  }else if (stype == 9){
    return '激励视频'
  }
  return '-'
}
//格式化时间
export function DateFormat(date,fmt='') {
	if (fmt == '' || fmt == undefined){
		fmt = 'YYYY-mm-dd HH:MM'
	}
	let ret="";
      date=new Date(date);
      const opt = {
        'Y+': date.getFullYear().toString(), // 年
        'm+': (date.getMonth() + 1).toString(), // 月
        'd+': date.getDate().toString(), // 日
        'H+': date.getHours().toString(), // 时
        'M+': date.getMinutes().toString(), // 分
        'S+': date.getSeconds().toString() // 秒
      }
      for (let k in opt) {
        ret = new RegExp('(' + k + ')').exec(fmt)
        if (ret) {
          fmt = fmt.replace(
            ret[1],
            ret[1].length == 1 ? opt[k] : opt[k].padStart(ret[1].length, '0')
          )
        }
      }
      return fmt
}
//返回数据类型
export function getOftype(argument) {
  var _toString = Object.prototype.toString
  return _toString.call(argument).slice(8,-1)
}
//返回数据类型
export function getCost(number,dec) {
  if (dec == 1){
    return parseInt(number)
  }
  number = number.replaceAll(',','')
  number = number.replaceAll(' ','')
  var numbers = number.split('.')
  if (numbers.length >= 2){
    var deeee = numbers[1].split('')
    var ddd = ''
    if(deeee.length == 0){
      ddd = '00'
    }else if(deeee.length == 1){
      ddd = deeee[0] + '0'
    }else {
      ddd = deeee[0] + deeee[1]
    }
    if (ddd == ''){
      ddd = '00'
      // return parseInt(numbers[0])*100
    }
    return parseInt(numbers[0]+ddd)//*100 + parseInt(ddd)*100
  }else if (numbers.length == 1){
    return parseInt(numbers[0]+'00')
  }else{
    return 0
  }
}

/**
 * @description 格式化金额
 * @param number：要格式化的数字
 * @param decimals：保留几位小数 默认0位
 * @param isF：当前数值单位1分 2元 默认为1(分) 
 * @param decPoint：小数点符号 默认.
 * @param thousandsSep：千分位符号 默认为,
 */
export function formatMoney(number, decimals = 0,isF = 1, decPoint = '.', thousandsSep = ',') {
  number = (number + '').replace(/[^0-9+-Ee.]/g, '')
  let n = !isFinite(+number) ? 0 : +number
  if (isF == 1) {
    n = n/100
  }
  let prec = !isFinite(+decimals) ? 0 : Math.abs(decimals)
  let sep = (typeof thousandsSep === 'undefined') ? ',' : thousandsSep
  let dec = (typeof decPoint === 'undefined') ? '.' : decPoint
  let s = ''
  let toFixedFix = function (n, prec) {
    let k = Math.pow(10, prec)
    return '' + Math.ceil(n * k) / k
  }
  s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.')
  let re = /(-?\d+)(\d{3})/
  while (re.test(s[0])) {
    s[0] = s[0].replace(re, '$1' + sep + '$2')
  }
  if ((s[1] || '').length < prec) {
    s[1] = s[1] || ''
    s[1] += new Array(prec - s[1].length + 1).join('0')
  }
  return s.join(dec)
}
